package org.example.Soution001;

public class singleNumber {
    public static void main(String[] args) {
        singleNumber obj = new singleNumber();
        int[] nums={1};
        System.out.println(obj.singleNumber(nums));
    }

    public int singleNumber(int[] nums) {
        //排序+遍历
        //冒泡
        for(int i=0;i<nums.length;i++){
            for(int j=0;j<nums.length-i-1;j++){
                if(nums[j]>nums[j+1]){
                    swap(nums,j,j+1);
                }
            }
        }
        //遍历
        return findSingleNumber(nums);
    }

    public void swap(int[] nums,int a,int b) {
        int temp=nums[a];
        nums[a]=nums[b];
        nums[b]=temp;
    }

    public int findSingleNumber(int[] nums){
        for(int i=0;i<nums.length-1;i++){
            if(nums[i]==nums[i+1]){
                i++;
            }else{
                return nums[i];
            }
        }
        return nums[nums.length-1];
    }
}
